Type.registerNamespace("BM");

// CustomConstraint object

BM.CustomConstraint = function(leafItem, additionNode) {
    BM.CustomConstraint.initializeBase(this, [leafItem, additionNode]);
}

BM.CustomConstraint.prototype = {

    getFunctionName: function() {
        ///	<summary>
        ///	returns the name of the function to validate against
        ///	</summary>
        ///	<returns type="String" /> 
        return this.additionNode.innerHTML;
    },

    validatesAgainstFunction: function() {
        if (this.getFunctionName() == '') return true;
        try {
            var functionText = this.getFunctionName() + "('" + this.getValue() + "'";
            if (this.item.getId()) {
                functionText += ", '" + this.item.getId() + "'";
            }
            functionText += ")"
            return eval(functionText);
        } catch (e) {
            alert('Invalid function:' + functionText);
            return true;
        }
    },

    isMet: function() {
        return this.validatesAgainstFunction();
    },

    getDefaultErrorText: function() {
    return BM.Messages['CustomConstraintError'] + " " + this.getFunctionName();
    }
}

BM.Addition['CustomConstraint'] = BM.CustomConstraint;
BM.CustomConstraint.registerClass("BM.CustomConstraint", BM.Constraint);